package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.TradingPoolAccountLog;
import com.sc.nft.enums.TradingPoolAccountCategoryEnum;
import com.sc.nft.enums.TradingPoolAccountTypeEnum;
import com.sc.nft.mapper.TradingPoolAccountLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.Objects;

/**
 * @author PC
 * @description 针对表【sc_trading_pool_account_log(用户账户变化 log)】的数据库操作Dao
 * @createDate 2024-10-26 13:52:37
 */
@Slf4j
@Repository
public class TradingPoolAccountLogDao extends ServiceImpl<TradingPoolAccountLogMapper, TradingPoolAccountLog> {

    /**
     * 分页查询
     *
     * @param page
     * @param daoId
     * @param category
     * @param source
     * @param startTime
     * @param endTime
     * @return
     */
    public IPage<TradingPoolAccountLog> recordPage(IPage<TradingPoolAccountLog> page, Long daoId, TradingPoolAccountCategoryEnum category, TradingPoolAccountTypeEnum source, Date startTime, Date endTime) {
        LambdaQueryWrapper<TradingPoolAccountLog> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(TradingPoolAccountLog::getDaoId, daoId);
        wrapper.eq(TradingPoolAccountLog::getCategory, category);
        wrapper.eq(Objects.nonNull(source), TradingPoolAccountLog::getSource, source);
        wrapper.ge(Objects.nonNull(startTime), TradingPoolAccountLog::getOperationTime, startTime);
        wrapper.le(Objects.nonNull(endTime), TradingPoolAccountLog::getOperationTime, endTime);
        wrapper.orderByDesc(TradingPoolAccountLog::getOperationTime);
        return page(page, wrapper);
    }

    ;

}
